/**
* 作者: clz
* 日期: 2025-05-07 02:12:43
* 备注: 联盟运输中心信息
*/
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.server.game.commondata.mail.MailConstant;
import com.motu.monstercity.server.game.commondata.union.UnionBusiness;
import com.motu.monstercity.server.game.log.LogType;
import com.motu.monstercity.server.game.logic.MailManager;
import com.motu.monstercity.server.game.logic.UnionManager;
import com.motu.vertx.module.utility.toolset.Tool;
import io.vertx.core.json.JsonArray;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

public class UnionBusinessTaskInfo extends UnionBusinessTaskInfoModel {
	public UnionBusinessTaskInfo() {
		super();
	}


	public UnionBusinessTaskInfo(long unionId) {
		putId(unionId);
		ramdonBusinessTask();
	}

	//运输中心订单完成,发放奖励,并且刷新订单
	public void sendBuissnessReward(UnionBusiness unionBusiness) {
		ramdonBusinessTask();
		//给联盟所有人发放邮件奖励
		List<UnionMember> unionMemberList = UnionManager.getUnionMemberList(getId());
		for (UnionMember unionMember : unionMemberList) {
			UserUnion userUnionMember = UnionManager.getUserUnion(unionMember.getUserId());
			MailManager.sendSystemMailReplaceContent(userUnionMember.getId(), MailConstant.UNION_BUSINESS_REWARD_TITLE, MailConstant.UNION_BUSINESS_REWARD_CONTENT, unionBusiness.getRewardItemList(), LogType.UNION_BUSINESS_REWARD);
		}
	}

	/**
	 * 随机分配运输中心订单
	 */
	public void ramdonBusinessTask() {
		ConcurrentHashMap<Integer, UnionBusiness> unionBusinessMap =  UnionManager.getUnionBusinessMap();
		List<Integer> priorityList  = new ArrayList<>();
		for (UnionBusiness unionBusiness : unionBusinessMap.values()) {
			int priority = unionBusiness.getPriority();
			for (int i = 0; i < priority; i++) {
				priorityList.add(unionBusiness.getId());
			}
		}
		Collections.shuffle(priorityList);
		int randomIndex = Tool.getIntRandom(priorityList.size());
		int taskId = priorityList.get(randomIndex);
		putTaskId(taskId);//随机分配任务
		putNum(0);//订单进度归0
	}
}
